package com.steel.yfmall.cloud.assistant.user.impl;

import com.steel.yfmall.cloud.assistant.dto.para.user.ParaSaleAreaBean;
import com.steel.yfmall.cloud.assistant.dto.para.user.ParaSaleGroupInfoBean;
import com.steel.yfmall.cloud.assistant.po.user.StaffSaleArea;
import com.steel.yfmall.cloud.assistant.po.user.StaffSaleAreaExample;
import com.steel.yfmall.cloud.assistant.po.user.StaffSaleGroupInfo;
import com.steel.yfmall.cloud.assistant.po.user.StaffSaleGroupInfoExample;
import com.steel.yfmall.cloud.assistant.user.StaffSaleCodeService;
import com.steel.yfmall.cloud.assistant.user.mapper.StaffSaleAreaMapper;
import com.steel.yfmall.cloud.assistant.user.mapper.StaffSaleGroupInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yuchaohua
 * @version V1.0
 * @Title: StaffSalesCodeServiceImpl
 * @Package com.steel.yfmall.cloud.assistant.user.impl
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/1/21 17:52
 */
@Slf4j
@Service
public class StaffSaleCodeServiceImpl implements StaffSaleCodeService {


    /**
     * 获取销售地区集合
     * @Title: getSaleAreaListByPara
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @return java.util.List<com.steel.yfmall.cloud.assistant.po.user.StaffSaleArea>    返回类型
     * @author yuchaohua
     * @date 2021/1/21 18:03
     */
    @Override
    public List<StaffSaleArea> getSaleAreaListByPara(ParaSaleAreaBean paraBean){
        StaffSaleAreaExample example = new StaffSaleAreaExample();
        StaffSaleAreaExample.Criteria criteria = example.createCriteria();
        getSaleAreaSearchData(criteria,paraBean);
        return staffSaleAreaMapper.selectByExample(example);
    }

    /**
     * 销售区域查询条件拼接
     * @param criteria
     * @param paraBean
     */
    private void getSaleAreaSearchData(StaffSaleAreaExample.Criteria criteria, ParaSaleAreaBean paraBean) {
        if (criteria == null || paraBean == null) {
            return;
        }
        // 站点编码
        if (StringUtils.isNotBlank(paraBean.getSiteCode())){
            criteria.andSiteCodeEqualTo(paraBean.getSiteCode());
        }
        // 销售区域编码
        if (StringUtils.isNotBlank(paraBean.getSaleAreaCode())){
            criteria.andSaleAreaCodeEqualTo(paraBean.getSaleAreaCode());
        }
        // 销售区域编码集合
        if (CollectionUtils.isNotEmpty(paraBean.getSaleAreaCodeList())){
            criteria.andSaleAreaCodeIn(paraBean.getSaleAreaCodeList());
        }
    }


    /**
     * 获取销售组集合
     * @Title: getSaleGroupInfoListByPara
     * @Description: (这里用一句话描述这个方法的作用)
     * @Param paraBean 参数说明
     * @return java.util.List<com.steel.yfmall.cloud.assistant.po.user.StaffSaleGroupInfo>    返回类型
     * @author yuchaohua
     * @date 2021/1/21 18:04
     */
    @Override
    public List<StaffSaleGroupInfo> getSaleGroupInfoListByPara(ParaSaleGroupInfoBean paraBean) {
        StaffSaleGroupInfoExample example = new StaffSaleGroupInfoExample();
        StaffSaleGroupInfoExample.Criteria criteria = example.createCriteria();
        getSaleGroupSearchData(criteria,paraBean);
        return staffSaleGroupInfoMapper.selectByExample(example);
    }

    /**
     * 销售组查询条件拼接
     * @param criteria
     * @param paraBean
     */
    private void getSaleGroupSearchData(StaffSaleGroupInfoExample.Criteria criteria, ParaSaleGroupInfoBean paraBean) {
        if (null == criteria || null == paraBean) {
            return;
        }
        // 站点编码
        if (StringUtils.isNotBlank(paraBean.getSiteCode())){
            criteria.andSiteCodeEqualTo(paraBean.getSiteCode());
        }
        // 销售区域编码
        if (StringUtils.isNotBlank(paraBean.getSaleAreaCode())){
            criteria.andSaleAreaCodeEqualTo(paraBean.getSaleAreaCode());
        }
        // 销售区域编码集合
        if (CollectionUtils.isNotEmpty(paraBean.getSaleAreaCodeList())){
            criteria.andSaleAreaCodeIn(paraBean.getSaleAreaCodeList());
        }
        // 销售组编码
        if (StringUtils.isNotBlank(paraBean.getSaleGroupCode())){
            criteria.andSaleGroupCodeEqualTo(paraBean.getSaleGroupCode());
        }
        // 销售组编码集合
        if (CollectionUtils.isNotEmpty(paraBean.getSaleGroupCodeList())){
            criteria.andSaleGroupCodeIn(paraBean.getSaleGroupCodeList());
        }
    }


    @Resource
    private StaffSaleAreaMapper staffSaleAreaMapper;

    @Resource
    private StaffSaleGroupInfoMapper staffSaleGroupInfoMapper;

}
